package com.api.gbhg.liuwenbo.api;

import com.api.gbhg.liuwenbo.dao.DataBaseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.general.BaseBean;

import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * 组织架构操作权限
 */

@Path("gb/OperationAuthorityApi")
public class OperationAuthorityApi {
    private static final Logger LOGGER = LoggerFactory.getLogger("gbhg");
    private static List<String> sysadmin ;
    private static List<String> status1 ;
    private static List<String> status2 ;

    /*
    static{
        BaseBean baseBean = new BaseBean();
        sysadmin = baseBean.getPropValue("NonCentralTree","sysadmin");
        status1 = Arrays.asList(baseBean.getPropValue("NonCentralTree","status1").split(","));
        status2 = Arrays.asList(baseBean.getPropValue("NonCentralTree","status2").split(","));
    }
    */
    /**
     * 操作权限管理
     * 1： 有新增 删除 调整（最大）
     * 2： 没有删除，其他都有
     * 3： 新增 删除 调整 都没有
     * @param param
     * @return
     */
    @POST
    @Path("/getAuthType")
    @Produces(MediaType.APPLICATION_JSON)
    public Integer getAuthType(Map<String,Object> param){
        BaseBean baseBean = new BaseBean();
        sysadmin = Arrays.asList(baseBean.getPropValue("NonCentralTree","sysadmin"));
        status1 = Arrays.asList(baseBean.getPropValue("NonCentralTree","status1").split(","));
        status2 = Arrays.asList(baseBean.getPropValue("NonCentralTree","status2").split(","));
        LOGGER.info("getAuthType判断收入权限人员id："+param.get("id").toString());
        if (status1.contains(param.get("id")) || sysadmin.contains(param.get("id"))){
            LOGGER.info("权限1  有增删查改");
            return 1;
        }else if(DataBaseUtil.isAuthorityByUid(param.get("id").toString())){
            LOGGER.info("权限2  有增查改");
            return 2;
        }else{
            LOGGER.info("权限3  只能查看");
            return 3;
        }
    }
}
